package com.nextive.weightlogger.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.nextive.weightlogger.dao.SettingsDao;
import com.nextive.weightlogger.dao.WeightLogDao;

/**
 * This is the main activity, the one started when the app is launched.
 * 
 * It has no UI and it starts the settings activity if settings are not saved,
 * the log weight activity if there are no entries yet, or the weight history
 * activity otherwise.
 * 
 * @author Federico Baseggio <fedebaseggio@gmail.com>
 */
public class MainActivity extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		SettingsDao settingsDao = new SettingsDao(this);

		Intent intent;
		
		// Decide what activity to launch.
		if (!settingsDao.getSettingsValid()) {
			// Settings were never saved before or were saved but didn't pass
			// validation. Launch SettingsActivity.
			intent = new Intent(this, SettingsActivity.class);
		} else {
			// Settings are valid.
			intent = new Intent(this, WeightHistoryActivity.class);
		}

		intent.putExtra(SettingsActivity
				.INTENT_EXTRA_FIRST_ACTIVITY, true);
		startActivity(intent);
		finish();
	}
}
